﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace Lawyer.Web
{
    public partial class Shared : System.Web.UI.MasterPage
    {
        public string UserName = "";
        public int UserType = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            string url = Request.Url.AbsolutePath.Substring(1);
            
            LoadRootNav(url);
            
            
        }
        protected void Page_Init(object sender, EventArgs e)
        {
            CheckSession();
        }

        private void CheckSession()
        {
            if ((Session["UserName"] != null) && (Session["Type"].ToString().Equals("2")))
            {
                UserName = Session["UserName"].ToString();
            }
            else
            {
                string rtn = Request.Url.AbsolutePath;
                Response.Redirect("login.aspx?url=" + rtn);
            }
        }

        private void LoadRootNav(string url)
        {
            Hashtable navlist = new Hashtable();
            navlist.Add("dashboard.aspx","dashboard");
            navlist.Add("archive.aspx", "archive");
            navlist.Add("activity.aspx", "activity");
            navlist.Add("file.aspx", "file");
            navlist.Add("archiveadd.aspx", "archive");
            navlist.Add("archivelist.aspx", "archive");
            navlist.Add("archivelist.aspx?status=0", "archive");
            navlist.Add("archivelist.aspx?status=1", "archive");
            navlist.Add("archivelist.aspx?status=2", "archive");
            navlist.Add("archivelist.aspx?status=3", "archive");
            navlist.Add("archivelist.aspx?status=4", "archive");
            navlist.Add("activityadd.aspx", "activity");
            navlist.Add("activity.aspx?status=1", "activity");
            navlist.Add("activity.aspx?status=2", "activity");
            navlist.Add("activity.aspx?status=3", "activity");
            navlist.Add("activity.aspx?status=4", "activity");
            navlist.Add("fileadd.aspx", "file");
            navlist.Add("customlist.aspx", "contacts");
            navlist.Add("customadd.aspx", "contacts");
             navlist.Add("contacts.aspx", "contacts");

            
            if (url != null)
            {
                string item="";
                foreach(DictionaryEntry de in navlist)
                {
                    if (de.Key.ToString().Equals(url))
                    {
                         item= de.Value.ToString();
                    }
                }
                
                ScriptManager.RegisterStartupScript(this, this.GetType(), "keyname", "LoadPageNav('" + item + "');", true);
            }
            
        }
    }
}
